package keeto.com.vn.classified.task;

import java.io.IOException;

import keeto.com.vn.classified.core.ClassifiedCore;
import keeto.com.vn.classified.core.ClassifiedListener;
import keeto.com.vn.classified.network.IProtocol;
import keeto.com.vn.classified.request.GetAndroidProductProposedRequest;
import keeto.com.vn.classified.response.GetAndroidProductResponse;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import android.util.Log;

public class TaskGetAndroidProductProposed extends AbstractTask {
	
	String IGuaranteeStoreId;
	String iHightLight;
	int iPageLimit;
	int iPageNumber;
	String CategoryType;
	String CategoryID;
	String AreaIds;
	String Keywords;
	String SortBy;

	public TaskGetAndroidProductProposed(ClassifiedListener listener, ClassifiedCore core,String guaranteeStoreId,String hightLight,int pageLimit, int pageNumber,String categoryType, String CategoryID,String AreaIds,String Keywords,String SortBy) {
		super(listener, core);
		this.IGuaranteeStoreId = guaranteeStoreId;
		this.iHightLight = hightLight;
		this.iPageLimit = pageLimit;
		this.iPageNumber = pageNumber;
		this.CategoryType = categoryType;
		this.CategoryID = CategoryID;
		this.AreaIds = AreaIds;
		this.Keywords = Keywords;
		this.SortBy = SortBy;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException, IOException {
		GetAndroidProductProposedRequest request = new GetAndroidProductProposedRequest();
		request.setGuaranteeStoreId(IGuaranteeStoreId);
		request.setHightLight(iHightLight);
		request.setPageLimit(iPageLimit);
		request.setPageNumber(iPageNumber);
		request.setCategoryType(CategoryType);
		request.setCategoryid(CategoryID);
		request.setAreaIds(AreaIds);
		request.setKeywords(Keywords);
		request.setSortBy(SortBy);
		GetAndroidProductResponse response = json.getAndroidProductProposed(request);
		
		for (ClassifiedListener listener : listeners){
			listener.finishgetAndroidProductProposed(response.getReturnCode(), response.getListPromotions(), response.getListSuggest(),response.getListSuggestProduct(), response.getListFavorite(), response.isHasMore(), response.getPageCount());
		}
	}

	@Override
	public void timeoutCallback() {
		for (ClassifiedListener ilistener:core.copyAndReconstructListeners(listener)){
			ilistener.finishgetAndroidProductProposed(IProtocol.STATUS_CODE_CONNECTION_TIMEOUT_502, null, null, null,null, false,0);
		}
	}

}
